package com.mjk.manager.magicapi.core.core.logging;


import com.mjk.common.core.jdbc.service.log.model.BeeLogModel;
import com.mjk.common.core.jdbc.service.plus.idbservice.BeeDBService;
import com.mjk.common.tools.gson.GsonUtils;
import com.mjk.common.tools.springextend.BeeSpringBean;
import com.mjk.common.util.ClobUtils;
import com.mjk.common.util.MDCUtils;
import com.mjk.common.util.ObjectUtils;
import com.mjk.manager.magicapi.core.core.config.WebSocketSessionManager;
import io.seata.common.util.BlobUtils;
import org.apache.commons.collections.map.HashedMap;

import java.util.Date;
import java.util.Map;

/**
 * 日志上下文
 *
 * @author mxd
 */
public interface MagicLoggerContext {

    String LOGGER_NAME = "magic";

    ThreadLocal<String> SESSION = new InheritableThreadLocal<>();
    /**
     * magic 执行日志 保存
     */
    ThreadLocal<Map<String, BeeLogModel>> logs = new InheritableThreadLocal<>();



    /**
     * 打印日志
     * re
     *
     * @param logInfo 日志信息
     */
    static void println(String logInfo) {
        // 获取SessionId
        String sessionId = SESSION.get();
        if (sessionId != null) {
            WebSocketSessionManager.sendLogs(sessionId, logInfo);
            BeeLogModel log = logs.get() != null ? logs.get().get(MDCUtils.getTraceId()) : null;
            if (null != log) {
                if (ObjectUtils.isNotEmpty(logInfo))
                    log.addTemp(logInfo);
            }
        }
    }

    /**
     * 移除ThreadLocal中的sessionId
     */
    static void remove() {
        SESSION.remove();
    }

    /**
     * 生成appender
     */
    void generateAppender();
}
